//
//  CTVCrypto.m
//  Channltv
//
//  Created by Bruno Keymolen on 13/08/07.
//  Copyright 2007 channl.tv. All rights reserved.
//

#import "CTVCrypto.h"

	#include <openssl/evp.h>
	#include <openssl/err.h>


@implementation CTVCrypto


+(NSData*)md5Digest:(NSData*)plain{
	// compute an MD5 digest.
	EVP_MD_CTX mdctx;
	unsigned char md_value[EVP_MAX_MD_SIZE];
	int md_len;
	EVP_DigestInit(&mdctx, EVP_md5());
	EVP_DigestUpdate(&mdctx, [plain bytes], [plain length]);
	EVP_DigestFinal(&mdctx, md_value, (unsigned int*)&md_len);
	return [NSData dataWithBytes: md_value length: md_len];
}

+(NSData*)sha1Digest:(NSData*)plain{
// compute an SHA1 digest.
	EVP_MD_CTX mdctx;
	unsigned char md_value[EVP_MAX_MD_SIZE];
	int md_len;
	EVP_DigestInit(&mdctx, EVP_sha1());
	EVP_DigestUpdate(&mdctx, [plain bytes], [plain length]);
	EVP_DigestFinal(&mdctx, md_value,  (unsigned int*)&md_len);
	return [NSData dataWithBytes: md_value length: md_len];
}

@end
